import pygame
import sys
from pygame.locals import *
import bullet
import trank
import auto_trank

pygame.init()
HEIGHT,WIDTH = 1000,1000
SCREEN_SIZE = (HEIGHT,WIDTH)
screen = pygame.display.set_mode(SCREEN_SIZE)
#自定义事件
EVENT = pygame.USEREVENT + 1
pygame.time.set_timer(EVENT,1000) #每个 1000 毫秒触发一次

clock = pygame.time.Clock()
trank1 = trank.Trank()

trank2 = auto_trank.AutoTrank()

all_trank = pygame.sprite.Group()
all_trank.add(trank1)
all_trank.add(trank2)
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        elif event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                pygame.quit()
                sys.exit()
        elif event.type == EVENT:
            #在这写有关自主移动的程序
            pass
    screen.fill((0,0,0))

    #按键
    key = pygame.key.get_pressed()
    trank1.update(key)
    trank2.update(trank1.rect)
    #绘制坦克
    screen.blit(trank1.surf,trank1.rect)
    screen.blit(trank2.surf,trank2.rect)
    #绘制子弹
    if trank1.bullet.life == True:
        screen.blit(trank1.bullet.surf, trank1.bullet.rect)
        #print(trank1.bullet.rect)
    if trank2.bullet.life == True:
        screen.blit(trank2.bullet.surf, trank2.bullet.rect)
    pygame.display.flip()
    clock.tick(50)


